﻿using System;
using UnityEngine;
using UnityEngine.UI;

namespace RenderHeads.Media.AVProVideo
{
	// Token: 0x0200002E RID: 46
	[HelpURL("http://renderheads.com/product/avpro-video/")]
	[AddComponentMenu("AVPro Video/Update Stereo Material", 400)]
	public class UpdateStereoMaterial : MonoBehaviour
	{
		// Token: 0x0600012F RID: 303 RVA: 0x0000A338 File Offset: 0x00008538
		private void Awake()
		{
			this._cameraPositionId = Shader.PropertyToID("_cameraPosition");
			this._viewMatrixId = Shader.PropertyToID("_ViewMatrix");
			if (this._camera == null)
			{
				GlobalData.Debug_LogWarning("[AVProVideo] No camera set for UpdateStereoMaterial component. If you are rendering in stereo then it is recommended to set this.");
			}
		}

		// Token: 0x06000130 RID: 304 RVA: 0x0000A378 File Offset: 0x00008578
		private void SetupMaterial(Material m, Camera camera)
		{
			m.SetVector(this._cameraPositionId, camera.transform.position);
			m.SetMatrix(this._viewMatrixId, camera.worldToCameraMatrix.transpose);
		}

		// Token: 0x06000131 RID: 305 RVA: 0x0000A3BC File Offset: 0x000085BC
		private void LateUpdate()
		{
			Camera camera = this._camera;
			if (camera == null)
			{
				camera = Camera.main;
			}
			if (this._renderer == null && this._material == null)
			{
				this._renderer = base.gameObject.GetComponent<MeshRenderer>();
			}
			if (camera != null)
			{
				if (this._renderer != null)
				{
					this.SetupMaterial(this._renderer.material, camera);
				}
				if (this._material != null)
				{
					this.SetupMaterial(this._material, camera);
				}
				if (this._uGuiComponent != null)
				{
					this.SetupMaterial(this._uGuiComponent.material, camera);
				}
			}
		}

		// Token: 0x04000139 RID: 313
		[Header("Stereo camera")]
		public Camera _camera;

		// Token: 0x0400013A RID: 314
		[Header("Rendering elements")]
		public MeshRenderer _renderer;

		// Token: 0x0400013B RID: 315
		public Graphic _uGuiComponent;

		// Token: 0x0400013C RID: 316
		public Material _material;

		// Token: 0x0400013D RID: 317
		private int _cameraPositionId;

		// Token: 0x0400013E RID: 318
		private int _viewMatrixId;
	}
}
